home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / NextAnswers / 1231_malloc_debug_problems.rtf < prev    next >
Text File  |  1995-06-12  |  3KB  |  74 lines

  1. {\rtf0\ansi{\fonttbl\f0\fnil Times-Roman;\f1\fmodern Courier;\f2\fmodern Ohlfs;}
  2. \paperw12940
  3. \paperh9000
  4. \margl120
  5. \margr1000
  6. {\colortbl;\red0\green0\blue0;}
  7. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\f0\b0\i0\ulnone\fs28\fc0\cf0 Q:  When linking my program with 
  8. \b MallocDebug
  9. \b0 ,  I get the error message\
  10. \
  11.     
  12. \f1\fs24 failed on vm_allocate
  13. \f0\fs28 \
  14.     \
  15. in the console when I tried to allocate 43 MB.  However, if I relink the exact same program without the 
  16. \b MallocDebug
  17. \b0  library,  it runs fine.  Why?\
  18. \
  19. Q:  When linking in 
  20. \b MallocDebug
  21. \b0 , I noticed that my program  VSIZE (using 
  22. \b ps -ux
  23. \b0 )  which was 2MB without 
  24. \b MallocDebug
  25. \b0 , would start out way high—well over 20MB.  Why?\
  26. \
  27. A:  
  28. \pard\tx1140\tx2300\tx3440\tx4600\tx5760\tx6900\tx8060\tx9200\tx10360\tx11520\fc1\cf1 The problem is that 
  29. \b MallocDebug
  30. \b0  requires all of the memory to be allocated contiguously, which means that it must guess how much the program might need and allocate all of that at once at
  31. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fc1\cf1  the
  32. \pard\tx1140\tx2300\tx3440\tx4600\tx5760\tx6900\tx8060\tx9200\tx10360\tx11520\fc1\cf1  beginning  The current gue
  33. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fc1\cf1 s
  34. \pard\tx1140\tx2300\tx3440\tx4600\tx5760\tx6900\tx8060\tx9200\tx10360\tx11520\fc1\cf1 timate is 40
  35. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fc1\cf1  
  36. \pard\tx1140\tx2300\tx3440\tx4600\tx5760\tx6900\tx8060\tx9200\tx10360\tx11520\fc1\cf1 M
  37. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fc1\cf1 B
  38. \pard\tx1140\tx2300\tx3440\tx4600\tx5760\tx6900\tx8060\tx9200\tx10360\tx11520\fc1\cf1 .  
  39. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fc1\cf1 This is the reason why when running your program with 
  40. \b MallocDebug
  41. \b0 , you have noticed that the VSIZE went up tremendously.\
  42.  
  43. \pard\tx1140\tx2300\tx3440\tx4600\tx5760\tx6900\tx8060\tx9200\tx10360\tx11520\fc1\cf1 \
  44. So if you use 
  45. \b MallocDebug
  46. \b0 ,  you can only ask for a total of 40 MB over the life of your program. After you cross that barrier,  it fails.  It doesn't matter if you have freed any or all of the memory you have previously asked for.  The indicative error message is : 
  47. \f1\fs24 "failed on vm_allocate"
  48. \f0\fs28  when you try to use 
  49. \b malloc()
  50. \b0 ,
  51. \b   calloc()
  52. \b0 ,
  53. \b  
  54. \b0 or
  55. \b  realloc()
  56. \b0 .  \
  57. \
  58. There is no workaround other than running your program without using 
  59. \b MallocDebug
  60. \b0 . \
  61.  
  62. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fc0\cf0 Note also that 
  63. \b MallocDebug
  64. \b0  cannot currently  be used together with 
  65. \b ProcessMonitor
  66. \b0 .\
  67. \
  68.  
  69. \fc1\cf1 QA818\
  70. \
  71. Valid for 2.0, 3.0\
  72. \
  73.  
  74.